import { CreateWindowOptions } from '@renderer/types/createWindow'
import { defineStore } from 'pinia'
import { useStyleStore } from '../globalStyle/style'

export const useMenusStore = defineStore('menus', {
  state: () => ({
    menus: [
      {
        name: '文件',
        children: [
          {
            name: '保存',
            key: 'fileSave'
          },
          {
            name: '导入',
            key: 'fileImport'
          }
        ]
      },
      {
        name: '画布',
        children: [
          {
            name: '清空画布',
            key: 'canvasClear'
          }
        ]
      },
      {
        name: '功能',
        children: [
          {
            name: '线体指标',
            key: 'lineIndicator'
          },
          {
            name: '单机精进',
            key: 'machineRefinement'
          }
        ]
      },
      {
        name: '窗口',
        children: [
          {
            name: '资源栏',
            key: 'windowResource'
          },
          {
            name: '属性栏',
            key: 'windowProperty'
          },
          {
            name: '消息栏',
            key: 'windowMessage'
          },
          {
            name: 'svg设置',
            key: 'svgSetting'
          },
          {
            name: '随机函数',
            key: 'randomFunction'
          }
        ]
      },
      {
        name: '帮助',
        children: [
          {
            name: '帮助文档',
            key: 'helpDoc'
          }
        ]
      }
    ]
  }),
  getters: {},
  actions: {
    menuClick(name: string) {
      switch (name) {
        case '保存':
          // 另存为
          window.electron.ipcRenderer.send('saveCanvasFile')
          break
        case '导入':
          // 导入
          window.electron.ipcRenderer.send('openCanvasFile')
          break
        case '清空画布':
          window.api.handleCanvasData('clearCanvas', 'resourceMana', true, [])
          break
        case '资源栏':
          useStyleStore().resizeResource(13)
          break
        case '属性栏':
          useStyleStore().resizeAttribute(15)
          break
        case '消息栏':
          useStyleStore().resizeMessage(15)
          break
        case 'svg设置':
          // svg设置
          this.openSvgSetting()
          break
        case '随机函数':
          this.openRandomFunction()
          break
        case '帮助文档':
          break
        case '线体指标':
          this.openLineIndicator()
          break
        case '单机精进':
          this.openMachineRefinement()
          break
        default:
          break
      }
    },

    //打开svg设置窗口
    openSvgSetting() {
      const obj = {} as CreateWindowOptions
      obj.key = 'svgSetting'
      obj.title = 'SVG设置'
      window.electron.ipcRenderer.send('openChild', obj)
    },

    //打开随机函数窗口
    openRandomFunction() {
      const obj = {} as CreateWindowOptions
      obj.key = 'randomFunction'
      obj.title = '随机函数'
      window.electron.ipcRenderer.send('openChild', obj)
    },

    //打开线体指标窗口
    openLineIndicator() {
      const obj = {} as CreateWindowOptions
      obj.key = 'lineIndicators'
      obj.title = '线体指标'
      window.electron.ipcRenderer.send('openChild', obj)
    },

    //打开单机精进窗口
    openMachineRefinement() {
      const obj = {} as CreateWindowOptions
      obj.key = 'refinement'
      obj.title = '设备节拍标准工时'
      obj.width = 1000
      obj.height = 750
      window.electron.ipcRenderer.send('openChild', obj)
    }
  }
})
